<?php

namespace AlibabaCloud;

use AlibabaCloud\Client\AlibabaCloud;

class Vod
{

  private $option;

  /**
   * 实例化
   * @param array $options
   * @throws Client\Exception\ClientException
   */
  public function __construct($options = [])
  {
    $opt = config('cloud.alibaba');
    if (!empty($options)) $opt = array_merge($opt, $options);
    $this->option = $opt;
    AlibabaCloud::accessKeyClient($opt['accessKeyId'], $opt['accessSecret'])
        ->regionId("cn-hangzhou")
        ->asDefaultClient();
  }

  /**
   * 直接执行指定方法
   * @param $fun
   * @param array $params
   * @return mixed
   * @throws Client\Exception\ClientException
   * @throws Client\Exception\ServerException
   */
  public function execFun($fun, $params = [])
  {
    $result = AlibabaCloud::rpc()
        ->product('vod')
        // ->scheme('https') // https | http
        ->version('2017-03-21')
        ->action($fun)
        ->method('POST')
        ->host('vod.cn-shanghai.aliyuncs.com')
        ->options($params)
        ->request();
    return $result->toArray();
  }

}